向網頁10.211.55.10:12345發送GET Request。用其他verbs只要替換掉就可以了。
10.211.55.10:12345
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def hello():
remote_addr = request.remote_addr
headers = request.headers
return f'Remote Address: {remote_addr}<br><br>Headers: {headers}'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=12345)
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
// build http client
client := &http.Client{}
// build get request
getURL := "http://10.211.55.10:12345/"
getReq, err := http.NewRequest("GET", getURL, nil)
if err != nil {
fmt.Println("Error creating GET request:", err)
return
}
// set HTTP 1.1 Keep-Alive header
getReq.Header.Set("Connection", "keep-alive")
// 發送10個get request
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
// execute get request
getResp, err := client.Do(getReq)
if err != nil {
fmt.Println("Error sending GET request:", err)
return
}
defer getResp.Body.Close()
body, err := io.ReadAll(getResp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
fmt.Println("response body:", string(body))
}()
wg.Wait()
}
}
Flask web response:
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip
response body: Remote Address: 10.211.55.2<br><br>Headers: Host: 10.211.55.10:12345
User-Agent: Go-http-client/1.1
Connection: keep-alive
Accept-Encoding: gzip